package com.springcloud.config.ribbon;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RoundRobinRule;

@Configuration
@RibbonClient(name = "microservice-provider-user", configuration = UserRibbonConfig.class)
public class RibbonConfig {

	@Bean
	@LoadBalanced // 带有负载均衡的
	public RestTemplate restTemplateBalance() {
		return new RestTemplate();
	}

	@Bean
	public IRule ribbonRule() {
		// BestAvailableRule 选择并发最少的
		// RoundRobinRule 轮询
		return new RoundRobinRule();// 轮询
	}
}
